package com.frinder.official.akka.test;

import akka.actor.AbstractActor;
import akka.actor.ActorRef;
import com.frinder.official.spring.MyBaseActor;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * Created by frinder on 2017/10/12.
 */
@Component
@Scope("prototype")
public class SomeActor extends MyBaseActor {
    ActorRef target = null;

    @Override
    public AbstractActor.Receive createReceive() {
        return receiveBuilder()
                .matchEquals("hello", message -> {
                    log.info("**************************** {}", message);
                    getSender().tell("world", getSelf());
                    if (target != null) target.forward(message, getContext());
                })
                .match(ActorRef.class, actorRef -> {
                    log.info("**************************** {}", actorRef);
                    target = actorRef;
                    getSender().tell("done", getSelf());
                })
                .build();
    }
}
